package com.laolang.shop.common.data.mvc.jackson;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 * @author khlbat
 * @version 1.0
 * @date 2020/11/1 20:46
 */
public class BigDeciamlJsonSerializer extends JsonSerializer<BigDecimal> {
    @Override
    public void serialize(BigDecimal bigDecimal, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        DecimalFormat format = new DecimalFormat("0.00");
        jsonGenerator.writeString(format.format(bigDecimal));

    }
}